/**
 * @copyright 2018 indie Semiconductor
 *
 * This file is proprietary to indie Semiconductor.
 * All rights reserved. Reproduction or distribution, in whole
 * or in part, is forbidden except by express written permission
 * of indie Semiconductor.
 *
 * @file pwm_sfr.h
 */

#ifndef __PWM_SFR_H__
#define __PWM_SFR_H__

#include <stdint.h>

/* -------  Start of section using anonymous unions and disabling warnings  ------- */
#if   defined (__CC_ARM)
  #pragma push
  #pragma anon_unions
#elif defined (__ICCARM__)
  #pragma language=extended
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
  #pragma clang diagnostic push
  #pragma clang diagnostic ignored "-Wc11-extensions"
  #pragma clang diagnostic ignored "-Wreserved-id-macro"
#elif defined (__GNUC__)
  /* anonymous unions are enabled by default */
#elif defined (__TMS470__)
  /* anonymous unions are enabled by default */
#elif defined (__TASKING__)
  #pragma warning 586
#elif defined (__CSMC__)
  /* anonymous unions are enabled by default */
#else
  #warning Not supported compiler type
#endif

/**
 * @brief A structure to represent Special Function Registers for PWM.
 */
typedef struct {

  union {
    struct {
      uint8_t  PRESCL                   :  8; /*!< Prescaler select */
      uint32_t PERIOD                   : 18;
      uint8_t                           :  6; /*   (reserved) */
    };
    uint32_t WORD;
  } CYCLE; /* +0x000 */

  uint32_t ENAREQ;                            /* +0x004 */

  uint32_t ENASTS;                            /* +0x008 */

  uint32_t INIT;                              /* +0x00C */

  uint32_t INVERT;                            /* +0x010 */

  uint8_t  UPDATE;                            /* +0x014 */
  uint8_t  _RESERVED_15[3];                   /* +0x015 */
  
  uint32_t   PWIDTH[24];
//  uint32_t PWIDTH0;                           /* +0x018 */
//
//  uint32_t PWIDTH1;                           /* +0x01C */
//
//  uint32_t PWIDTH2;                           /* +0x020 */
//
//  uint32_t PWIDTH3;                           /* +0x024 */
//
//  uint32_t PWIDTH4;                           /* +0x028 */
//
//  uint32_t PWIDTH5;                           /* +0x02C */
//
//  uint32_t PWIDTH6;                           /* +0x030 */
//
//  uint32_t PWIDTH7;                           /* +0x034 */
//
//  uint32_t PWIDTH8;                           /* +0x038 */
//
//  uint32_t PWIDTH9;                           /* +0x03C */
//
//  uint32_t PWIDTH10;                          /* +0x040 */
//
//  uint32_t PWIDTH11;                          /* +0x044 */
//
//  uint32_t PWIDTH12;                          /* +0x048 */
//
//  uint32_t PWIDTH13;                          /* +0x04C */
//
//  uint32_t PWIDTH14;                          /* +0x050 */
//
//  uint32_t PWIDTH15;                          /* +0x054 */
//
//  uint32_t PWIDTH16;                          /* +0x058 */
//
//  uint32_t PWIDTH17;                          /* +0x05C */
//
//  uint32_t PWIDTH18;                          /* +0x060 */
//
//  uint32_t PWIDTH19;                          /* +0x064 */
//
//  uint32_t PWIDTH20;                          /* +0x068 */
//
//  uint32_t PWIDTH21;                          /* +0x06C */
//
//  uint32_t PWIDTH22;                          /* +0x070 */
//
//  uint32_t PWIDTH23;                          /* +0x074 */

  union {
    struct {
      uint8_t  ENASTAGGERSTART          :  1;
      uint8_t                           :  3; /*   (reserved) */
      uint8_t  INTERVALSEL              :  3; /*!< Interval select */
      uint8_t                           :  1; /*   (reserved) */
      uint32_t                          : 24; /*   (reserved) */
    };
    uint32_t WORD;
  } STAGGER; /* +0x078 */

  union {
    struct {
      union {
        struct {
          uint8_t  PERIOD               :  1; /*!< Period interrupt enable */
          uint8_t  UPD                  :  1; /*!< Updated interrupt enable */
          uint8_t                       :  6; /*   (reserved) */
        };
        uint8_t BYTE;
      } ENABLE;
      union {
        struct {
          uint8_t  PERIOD               :  1; /*!< Period interrupt clear */
          uint8_t  UPD                  :  1; /*!< Updated interrupt clear */
          uint8_t                       :  6; /*   (reserved) */
        };
        uint8_t BYTE;
      } CLEAR;
      union {
        struct {
          uint8_t  PERIOD               :  1; /*!< Period interrupt status */
          uint8_t  UPD                  :  1; /*!< Updated interrupt status */
          uint8_t                       :  6; /*   (reserved) */
        };
        uint8_t BYTE;
      } STATUS;
      union {
        struct {
          uint8_t  PERIOD               :  1; /*!< Period interrupt active */
          uint8_t  UPD                  :  1; /*!< Updated interrupt active */
          uint8_t                       :  6; /*   (reserved) */
        };
        uint8_t BYTE;
      } IRQ;
    };
    uint32_t WORD;
  } PWMIRQ; /* +0x07C */

  uint32_t PWMCNT;                            /* +0x080 */

} PWM_SFRS_t;

/* --------  End of section using anonymous unions and disabling warnings  -------- */
#if   defined (__CC_ARM)
  #pragma pop
#elif defined (__ICCARM__)
  /* leave anonymous unions enabled */
#elif (__ARMCC_VERSION >= 6010050)
  #pragma clang diagnostic pop
#elif defined (__GNUC__)
  /* anonymous unions are enabled by default */
#elif defined (__TMS470__)
  /* anonymous unions are enabled by default */
#elif defined (__TASKING__)
  #pragma warning restore
#elif defined (__CSMC__)
  /* anonymous unions are enabled by default */
#else
  #warning Not supported compiler type
#endif

/**
 * @brief The starting address of PWM SFRS.
 */
#define PWM_SFRS ((__IO PWM_SFRS_t *)0x50011000)

#endif /* end of __PWM_SFR_H__ section */


